#re模块的3个基础匹配方法

#
import re
from traceback import print_tb

s = "python 323 ititit### 5python@ 6666python"
#match 从头开始匹配
# result = re.match("python",s)
# print(result)
#
# #search  从头开始找第一个匹配的
# result = re.search("python",s)
# print(result)
#
# #findall 找出所有的匹配项
# result = re.findall("python",s)
# print(result)
#
# #pattern写法多样
# result = re.findall(r'\d',s) #字符串前面加上r，表示字符串中的转义字符无效
# print(result)
#
#
# result = re.findall(r'[a-zA-Z]',s)
# print(result)
#
# result = re.match(r'[a-zA-Z]',s)
# print(result)
#
# result = re.match(r'[a-zA-Z]',s)
# print(result)
#
# result = re.findall(r'[pyth]',s)
# print(result)


#匹配账号，只能由字母和数字组成，长度限制6到10位
r = '^[0-9a-zA-Z]{6,10}$' #^表示从头开始，$表示结尾
src = '1234312a'
print(re.findall(r,src))
#匹配qq号，要求纯数字，长度5-11，第一位不为0
r = '^[1-9][0-9]{4,10}$'
src = '0123123'
print(re.findall(r,src))
#匹配邮箱地址：只允许qq，163，gmail三种邮箱地址
r = r'^[\w-]+(\.[\w-]+)*@(qq|163|gmail)(\.[\w-]+)+$'
src = '2.40299.4289@qq.com'
print(re.match(r,src))